﻿using System.Linq;
using System.Web;
using Common.Objects;
using EYCmsAdmin.Domain.IDomainServices;
using EYCmsAdmin.Domain.Models;
using EYCmsAdmin.Presentation.IPresentationServices;
using EYCmsAdmin.Presentation.Models.MenuModels;

namespace EYCmsAdmin.Presentation.PresentationServices
{
    public class MenuPresentationService : IMenuPresentationService
    {
        private readonly IUserDomainService userDomainService;

        public MenuPresentationService(IUserDomainService userDomainService)
        {
            this.userDomainService = userDomainService;
        }

        public SectionMenuModel GetSectionMenu()
        {
            SystemUser currentUser = HttpContext.Current.User as SystemUser;

            if (currentUser != null)
            {
                User user = userDomainService.GetUserByLogin(currentUser.Login);
                SectionMenuModel sectionModel = new SectionMenuModel(user.Permissions.Select(x => x.Name));
                return sectionModel;
            }

            return new SectionMenuModel();
        }
    }
}